
//生成5位验证码，其中4位为字母，一个为数字，数字的位置可以任意

import java.util.Arrays;
import java.util.Random;

public class Test2 {
    public static void main(String[] args) {
        //构建字母数组
        char[] crr = new char[52];
        crr[0] = 'a';
        //将a-z 和 A-Z 放入数组
        for (int i = 1; i < 26; i++) {
            crr[i] = (char)(crr[i-1]+1);
        }
        crr[26] = 'A';
        for (int i = 27; i < crr.length; i++) {
            crr[i] = (char)(crr[i-1]+1);
        }

//        System.out.println(Arrays.toString(crr));
        //设置随机数
        Random random = new Random();

        //设置容量
        StringBuilder strB = new StringBuilder();
        int index = 0;
        //生成4个随机字母
        for (int i = 0; i < 4; i++) {
            index = random.nextInt(crr.length);
            strB.append(crr[index]);
        }

        //添加数组
        strB.append(random.nextInt(10));

        //转变成字符串
        String str = strB.toString();
//        System.out.println(str);

        //转变成字符数组
        char[] crrStr = str.toCharArray();
        index = random.nextInt(crrStr.length);
        char tmp = crrStr[crrStr.length-1];
        crrStr[crrStr.length-1] = crrStr[index];
        crrStr[index] = tmp;

        //转为字符串
        str = new String(crrStr);

        System.out.println(str);

    }
}
